package cn.yr.oauth.configuration;

import cn.yr.oauth.properties.GiteeProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthGiteeRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(GiteeProperties.class)
@ConditionalOnProperty(
        prefix = "oauth.gitee",
        name = "clientId"
)
public class GiteeConfiguration {


    @Autowired
    private GiteeProperties giteeProperties;

    @Bean
    public AuthGiteeRequest getAuthGiteeRequest(){
        return new AuthGiteeRequest(AuthConfig.builder()
                .clientId(giteeProperties.getClientId())
                .clientSecret(giteeProperties.getClientSecret())
                .redirectUri(giteeProperties.getRedirectUrl())
                .build());
    }

}
